package com.design.pattern.structure.decorator.mybatiscache.v2;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CacheExecutor implements Executor{
    private Executor executor;

    static Map<String, Object> cache = new ConcurrentHashMap<>();



    public CacheExecutor(Executor executor) {
        this.executor = executor;
    }

    @Override
    public Object query() {
        System.out.println("从缓存中取数据");
        Object result = cache.get("sqlId");
        if(result != null) {
            return result;
        }else {
            System.out.println("查询数据库");
            return "数据库数据";
        }
    }
}
